<template>
  <div class="IntelligentPushList">
    <div class="header-top">
      <ul class="tablist">
        <li :class="active==0?`active`:``"> 智能推送</li>
      </ul>
      <div class="head-right">
        <el-button @click="getSetSendPage" icon="el-icon-setting" v-hasPermi="['IntelligentPushList:send']">发送设置</el-button>
      </div>
    </div>

    <div class="container-big">
      <div class="container-right">
        <div class="content-big">
          <div class="content-tabel">
            <div class="content-head">
              <div class="content-left">
                <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="130px">
                  <el-button size="small" type="primary" icon="el-icon-plus" v-hasPermi="['IntelligentPushList:add']"  @click="handleAddOrEidt('add')">添加推送</el-button>
                  <el-form-item prop="userName1">
                    <el-select v-model="queryParams.userName2" size="small" filterable placeholder="状态" @change="handleQuery">
                      <el-option
                        v-for="item in statusList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item prop="userName1">
                    <el-select v-model="queryParams.userName2" size="small" filterable placeholder="类型" @change="handleQuery">
                      <el-option
                        v-for="item in typeList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                      </el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item v-model="queryParams.userName2">
                    <el-date-picker
                      v-model="dateRange1"
                      value-format="yyyy-MM-dd"
                      type="daterange"
                      range-separator="-"
                      size="small"
                      start-placeholder="开始时间"
                      end-placeholder="结束时间"
                      @change="handleQuery"
                    ></el-date-picker>
                  </el-form-item>
                  <el-form-item>
                    <div class="search">
                      <el-input v-model="queryParams.userName1" size="small" placeholder="标签组/标签名" clearable/>
                      <el-button icon="el-icon-search" size="small" @click="handleQuery"></el-button>
                    </div>
                  </el-form-item>
                </el-form>
              </div>
            </div>
            <el-table
              :data="tableDataList"
              ref="companylabelList"
              @selection-change="handleSelectionChange"
            >
              <el-table-column
                :label="item.label"
                align="center"
                v-for="(item, index) in tableColumns"
                :key="index"
                :prop="item.key"
                :min-width="item.minWidth ? item.minWidth : ``"
                :fixed="item.fixed ? item.fixed : false"
                :show-overflow-tooltip="true"
              >
                <template slot="header" v-if="item.showHeaderTip">
                  <div>
                    {{ item.label }}
                    <el-tooltip effect="dark" :content="item.showHeaderTip" placement="top">
                      <span><i class="el-icon-question"></i></span>
                    </el-tooltip>
                  </div>
                </template>
                <!--用于表格自定义-->
                <template slot-scope="scope">
                  <div v-if="item.key=='name'">
                    <div class="table-title">推送1</div>
                    <div class="plan-code">流程id:333</div>
                  </div>
                  <div v-else style="text-align: center">{{ scope.row[item.key] }}</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="created_at"
                label="操作"
                width="420"
                fixed="right"
                align="center"
              >
                <template slot-scope="scope">
                  <div class="group-btn">
                    <el-button type="text" v-hasPermi="['IntelligentPushList:close']"  @click="handleMgt(scope.row)">暂停</el-button>
                    <el-button type="text" v-hasPermi="['IntelligentPushList:open']"  @click="handleMgt(scope.row)">开启</el-button>
                    <el-button type="text" v-hasPermi="['IntelligentPushList:cancel']" @click="handleApplication" >取消</el-button>
                    <el-button type="text" v-hasPermi="['IntelligentPushList:data']">数据</el-button>
                    <el-button type="text" v-hasPermi="['IntelligentPushList:edit']" @click="handleAddOrEidt('edit',scope.row)">编辑</el-button>
                    <el-button type="text"  v-hasPermi="['IntelligentPushList:mgt']" @click="handlView(scope.row)">管理</el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <pagination
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
          </div>
        </div>
      </div>
    </div>
    <setSendPage v-if="showSetSendPage" :visableIf.sync="showSetSendPage"></setSendPage>
  </div>

</template>

<script>
import {listUser, delUser,} from "@/api/system/user";

export default {
  name: "IntelligentPushList",
  components: {
    'setSendPage': () => import('./setSendPage.vue'),
  },
  data() {
    return {
      showSetSendPage:false,
      showAddOrEditRule: false,//添加编辑规则
      showSetRrulescheme: false,//设置
      showApplicationPage: false,//应用
      active: 0,
      dialogType: 'add',
      dateRange1: [],
      statusList: [
        //分组类型
        {value: 1, label: "创建中"},
        {value: 2, label: "等待中"},
        {value: 3, label: "技术组"},
      ],
      typeList: [
        {value: 1, label: "定时型-单次"},
        {value: 2, label: "定时型-重复"},
        {value: 3, label: "触发型完成"},
      ],
      showExportPage: false,//导出
      tableHeight: 600,
      tableColumns: [
        {key: 'name', label: `计划名称`, visible: true, minWidth: 150, fixed: true},
        {key: 'label', label: `状态`, visible: true, minWidth: 150, fixed: false},
        {key: 'label2', label: `类型`, visible: true, minWidth: 150, fixed: false},
        {key: 'label3', label: `累计进入`, visible: true, minWidth: 150, fixed: false, showHeaderTip: '累计需要触达的客户数',},
        {key: 'label4', label: `累计触达`, visible: true, minWidth: 150, fixed: false, showHeaderTip: '实际已触达完成的客户数，不包含取消的客户',},
        {key: 'label5', label: `累计完成目标`, visible: true, minWidth: 150, fixed: false, showHeaderTip: '触达客户中,完成目标的客户数',},
        {key: 'label6', label: `目标完成率`, visible: true, minWidth: 150, fixed: false},
        {key: 'label7', label: `创建时间`, visible: true, minWidth: 150, fixed: false},
      ],
      tableDataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,//用户id
        userName1: null,

      },
      total: 8, // 表格的总条数
    };
  },
  created() {
    // this.getList();
    this.tableDataList = [];
    for (let i = 0; i < 2; i++) {
      let obj = {
        name: '小红',
        label1: '18207418337',
        label2: '18207418337',
        label3: '18207418337',
        label4: '18207418337',
      }
      this.tableDataList.push(obj);
    }
  },
  methods: {
    getAcitve(index) {
      this.active = index;
    },
    handleMgt(row) {
      this.showSetRrulescheme = true;
    },
    handleAddOrEidt(type, row) {
      if (type == 'add') {
        this.dialogType = 'add';
      } else if (type == 'edit') {
        this.dialogType = 'edit';
      }
      this.$router.push({
        path: '/IntelligentOperationMgt/IntelligentPush/addOrEditIntelligenPush',
        query: {
          dialogType: this.dialogType,
        }
      })
      // this.showAddOrEditRule = true;
    },
    handleNodeClick(data) {
      console.log(data);
    },
    showLabel() {
      this.showSelectLabelPage = true;
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tableDataList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(val) {
      this.multipleSelection = [];
      if (val && val.length > 0) {
        val.forEach((item) => {
          this.multipleSelection.push(item.id);
        })
        console.log('multipleSelection', this.multipleSelection);
      }
    },
    handleView(row) {
    },
    handleUpdate(row) {
      //修改
    },
    /** 管理按钮操作 */
    handlView(row) {
      this.$router.push({
        path:'/IntelligentOperationMgt/IntelligentPush/viewIntelligenPush',
        query:{

        },
      })
    },
    handleNumberDelete() {
      // const userIds = row.userId || this.ids;
      // this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function () {
      //   return delUser(userIds);
      // }).then(() => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // }).catch(() => {
      // });
      this.$msgBox.showMsgBox({
        title: "是否确认删除？",
        content: "该企微号正在执行服务，删除将会使该号从操作中释放，导致部分功能无法正常使用，请谨慎选择。*如该号已加入在线聊天，成功删除后，聊天记录会被一并删除，重新登录后无法恢复。",
      })
        .then(async (val) => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.showExportPage = true;
    },
    handleCustom() {
      this.showCustomListPage = true;
    },
    handerTableLabel() {
      console.log('点击了打开标签',);
      this.showTableLabel = true;
    },
    handleSelectSmartTags() {
      //打开智能标签
      this.showSelectSmartTags = true;
    },
    handleApplication(row) {
      this.showApplicationPage = true;
    },
    getSetSendPage(){
     this.showSetSendPage=true;
    },
  }
};
</script>
<style lang="scss" scoped>
.tooltipContent {
  .h5 {
    font-size: 12px;
  }

  .list-big {
    display: flex;
    flex-wrap: wrap;

    span {
      height: 25px;
      display: flex;
      padding: 0px 5px;
      margin: 4px 4px 4px 0;
      color: rgba(0, 0, 0, .65);
      border: 1px dashed #eee;
    }
  }
}

.keywordList {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;

  .tips {
    color: #2d8cf0;
  }
}

.container-big {
  display: flex;
  height: calc(100vh - 100px);
  margin: 12px;

  .container-left {
    width: 278px;
    background: #fff;
    margin-right: 12px;
    padding: 20px;
    position: relative;

    .addIcon {
      position: absolute;
      right: 10px;
      top: 26px;

      i {
        margin: 0px 5px;
        font-size: 16px;
        font-weight: bold;
      }
    }

    .line {
      margin: 10px -20px;
      height: 1px;
      background: #eee;

    }

    .tablist {
      height: 50px;
      display: flex;
      justify-items: center;
      border-left: none;
      border-radius: 4px 0 0 4px;
      height: 32px;
      margin-bottom: 12px;
      position: relative;
      background: #fff;

      &:after {
        content: '';
        position: absolute;
        left: -40px;
        right: -40px;
        bottom: 0px;

      }

      li {
        display: flex;
        align-items: center;
        justify-items: center;
        border-left: 1px solid #e9e9e9;
        border-radius: 4px 0 0 4px;
        font-weight: bold;
        padding: 0px 10px;
        font-size: 14px;
        color: rgba(0, 0, 0, .65);
        border: 1px solid #eee;
        cursor: pointer;

        &.active {
          border-color: #3070ff;
          color: #3070ff;
        }
      }
    }
  }

  .container-right {
    flex: 1;
    background: #fff;

  }
}


.content-big {
  height: calc(100vh - 180px);
  overflow-y: auto;

  .el-form {
    background: #fff;
    border-radius: 8px;
    margin-top: -1px;

    .el-button {
      margin-right: 10px;
    }

    .el-form-item {
      margin-bottom: 0px;

      .right-big {
        border-radius: 4px;
        border: 1px solid #DCDFE6;
        padding-left: 11px;

        > span {
          color: #777;
          width: 89px;
          display: inline-block;
          white-space: nowrap;
        }

        .el-select {
          width: 138px;

          ::v-deep .el-input__inner {
            border: none;
          }
        }

        .el-input {
          width: 138px;

          ::v-deep .el-input__inner {
            border: none;
          }
        }

        ::v-deep .el-date-editor {
          border: none;
        }
      }

    }
  }

  .content-tabel {
    background: #fff;

    .content-head {
      height: 60px;
      display: flex;
      justify-content: space-between;
      padding: 16px;

      .content-left {
        display: flex;
        align-items: center;

        .el-button {
          .el-button--medium {
            padding: 8px 20px;
          }
        }

        .left-number {
          font-size: 12px;
          color: rgba(0, 0, 0, .45);
          margin-left: 10px;
        }

        .group-btn {

        }
      }

      .content-right {
        display: flex;
        align-items: center;

        .example {
          font-size: 14px;
          display: flex;
          align-items: center;
          margin-right: 20px;

          .el-switch {
            margin-right: 10px;
            margin-left: 5px;
          }
        }
      }
    }

    .el-table {
      margin-bottom: 20px;
    }
  }

  .pagination-container {
    height: 60px;
  }
}

.table-footer {
  position: fixed;
  left: 500px;
  right: 12px;
  bottom: 0;
  height: 56px;
  padding: 12px 16px;
  border-top: 1px solid #e9e9e9;
  background: #fff;
  z-index: 2;
  display: flex;
  justify-content: space-between;

  .footer-left {
    display: flex;
    align-items: center;

    .chooseAll {
      color: #5993ff;
      margin-right: 10px;
    }

    span {
      margin: 0px 10px;
      color: #5993ff;
    }
  }

  .footer-right {
    .el-dropdown {
      margin-right: 10px;

      .el-button--primary {
        border-radius: 4px;
        color: rgba(0, 0, 0, .65);
        border: 1px solid #e9e9e9;
        background: #fff;
      }
    }
  }
}

.userInfo {
  border-radius: 4px;
  margin: 8px 0;
  cursor: pointer;
  position: relative;
  padding-left: 50px;
  font-size: 14px;
  list-style: none;
  text-align: left;

  img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    left: 0px;
    top: 0px;
    position: absolute;
  }

  .label {
    margin-top: 2px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.label-list {
  label {
    font-size: 14px;
    line-height: 1.5715;
    word-wrap: break-word;
    font-weight: 400;
  }

  span {
    margin: 4px 4px 4px 0;
    font-size: 12px;
    height: 25px;
    line-height: 25px;
    white-space: nowrap;
    background: #f0f0f0;
    border: 1px solid #e9e9e9;
    border-radius: 4px;
    padding: 0px 7px;
    display: inline-block;

  }
}

.tablist {
  font-size: 14px;
  margin-right: 10px;
  display: flex;
  align-items: center;
  background: #fff;

  li {
    cursor: pointer;
    font-weight: 400;
    list-style: none;
    margin: 0px 10px;
    position: relative;
    display: flex;
    height: 44px;
    align-items: center;

    &.active {
      color: #3070ff;

      &:after {
        content: '';
        position: absolute;
        height: 2px;
        background: #3070ff;
        width: 100%;
        bottom: 0px;
        left: 0px;
      }
    }
  }

  .example-modal {
    position: fixed;
    left: 0;
    margin-top: 10px;
    display: none;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    background: #FFFFFF;

    .example-cover {
      height: 600px;
    }
  }
}

.search {
  display: flex;

  ::v-deep.el-input__inner {
    border-right: none !important;
    border-radius: 4px 0px 0px 0px;
  }

  ::v-deep .el-button--default {
    border-radius: 0px 4px 4px 0px;
    padding: 0px 10px;
  }
}

.table-title {
  color: #2d8cf0;
}

.plan-code {
  text-align: center;
}
.header-top {
  height: 46px;
  background: #fff;
  border-bottom: 1px solid #e9e9e9;
  position: relative;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;

  .head-right{
    position: absolute;
    height: 100%;
    display: flex;
    justify-items: center;
    right:30px;
    align-items: center;
    .el-button--medium {
      padding: 0px 12px !important;
      height: 32px;
      display: flex;
      justify-items: center;
      align-items: center;
    }
  }
  .divider {
    margin: 0 20px;
    width: 1px;
    height: 16px;
  }
}

</style>
